package com.qf.day08.zuoye02;

import java.util.Random;

public class BattleManger {
    /**
     * 组队ok
     * 每队3个选手
     * 如果某一堆的所有选手都阵亡，游戏结束
     * @param team1
     * @param Team2
     */
    public static void teamPk(Fightable[] team1,Fightable Team2){

    }
    /**
     * 两个Fightable  进行pk决出胜负
     * @param player1
     * @param player2
     */
    public static void pk(Fightable player1,Fightable player2){
        System.out.println("ok开始");

        int count=1;  //代表回合数

//        Fightable player2 = null;
        while (player1.isAlive()&& player2.isAlive()){
            System.out.println("第"+(count++)+"回合");
            Random random = new Random();
            int i = random.nextInt(2);
            if(i==0){
                System.out.println("player1先攻击");
                player1.fight(player2);

                //2要不要打回去呢
                //.被打的玩家是不是已经挂了，没有挂掉，就打回去
                if (player2.isAlive()) {
                    System.out.println("player2后攻击");
                    player2.fight(player1);
                }else {
                    System.out.println("player2被打败了游戏结束");
                }
            }else {
                //让2先攻击
                System.out.println("player2先攻击");
                player2.fight(player1);
                if (player1.isAlive()) {
                    System.out.println("player1后攻击");
                    player1.fight(player2);
                }else {
                    System.out.println("player1被打败了游戏结束");
                }
            }
            //打印每个回合结束后，打赢两个player的状态
            System.out.println(player1);
            System.out.println(player2);
        }
    }
}
